package com.forestar.mapControl.utils.mapConvert.task;

import android.graphics.Bitmap;
import android.os.Environment;

import com.forestar.mapControl.utils.LogD;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * created by  xzk
 * 2020/8/5   14:03
 * 说明:
 */
public abstract class LoadTileCommonTask implements Runnable{
//全部bitmap的集合
    List<Bitmap> bitmapTempList = new ArrayList<>();
    //按照文件夹（图层），保存的图片集合
    List<List<Bitmap>> multiLevelTempList = new ArrayList<>();
    //结束通知
    protected AtomicInteger hasTaskNum;
    //最大读取数量
    protected int fileMaxSize =10000;

    public List<Bitmap> getBitmapTempList() {
        return bitmapTempList;
    }

    public List<List<Bitmap>> getMultiLevelTempList() {
        return multiLevelTempList;
    }

    public LoadTileCommonTask(AtomicInteger hasTaskNum) {
        this.hasTaskNum = hasTaskNum;
    }

    //生成缓存文件夹
    public static String buildTempFileDirectory(){
        String tilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "testGis" + File.separator ;
        File file = new File(tilePath);
        if(!file.exists()){
            boolean mkdirs = file.mkdirs();
            if(!mkdirs){
                file.mkdirs();
            }
        }
        return tilePath;
    }

    @Override
    public void run() {
        //外层testGis文件夹
        long start = System.currentTimeMillis();
        getBitmapListFromFile();
        long end = System.currentTimeMillis();
        LogD.e("瓦片文件数量:图片数据加载完毕:耗时：" + (end - start) + "《-——数量--》" + bitmapTempList.size());
        if (null != hasTaskNum) {
            //以原子的方式当前值 -1
            hasTaskNum.decrementAndGet();
        }
    }

    public abstract void getBitmapListFromFile();
}
